package com.library.controller;

import com.library.base.BaseController;
import com.library.base.R;
import com.library.domain.vo.LoginUser;
import com.library.service.BookService;
import com.library.service.LendRecordService;
import com.library.service.ReaderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : 凉小天
 * @date : 2021/7/1 16:27
 */
@RestController
@RequestMapping("/dashboard")
public class DashboardController extends BaseController {
    @Resource
    private BookService bookService;
    @Resource
    private LendRecordService lendRecordService;
    @Resource
    private ReaderService readerService;
    /**
     * 统计数量
     */

    @GetMapping("/count")
    public R countLednRecords(){
        int visitCount = LoginUser.getVisitCount();
        int readerCount = readerService.count();
        int lendRecordCount = lendRecordService.count();
        int bookCount = bookService.count();
        Map<String ,Object> map = new HashMap<>();
        map.put("visitCount",visitCount);
        map.put("readerCount",readerCount);
        map.put("lendRecordCount",lendRecordCount);
        map.put("bookCount",bookCount);
        return result(map);
    }
}